/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.classdiagram.figures;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.MidpointLocator;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PositionConstants;

import com.cea.papyrus.core.figures.connection.EdgeFigure;

/**
 * Figure of the dependency link.
 * 
 * @author Patrick Tessier
 */
public class InterfaceRealizationFigure extends EdgeFigure  {
	
	/**
	 * 
	 */
	private int[] dashes =new int[10];
	
	/**
	 * 
	 */
	private Label label;
	
	/**
	 * 
	 */
	public InterfaceRealizationFigure() {
		PolygonDecoration dec = new PolygonDecoration();
		dec.setScale( 15, 5);
		dec.setBackgroundColor( ColorConstants.white);
		dec.setLineWidth(1);
		setTargetDecoration(dec); // arrow at target endpoint
		
		setForegroundColor( ColorConstants.black);
		
		
		this.setLineStyle(Graphics.LINE_CUSTOM);  // line drawing style

		label = new Label();
		label.setOpaque(true);
		MidpointLocator locator = new MidpointLocator(this, 0);
		locator.setRelativePosition(PositionConstants.NORTH); 
		add (label, locator);
		setLineWidth(1);
		for (int i=0;i<10;i++) {
			dashes[i]=5;
		}
	
	}
	
	/**
	 * 
	 * 
	 * @param text 
	 */
	public void setname(String text){
		label.setText(text);
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.draw2d.Shape#paintFigure(org.eclipse.draw2d.Graphics)
	 */
	/**
	 * 
	 * 
	 * @param graphics 
	 */
	@Override
	public void paintFigure(Graphics graphics) {
		graphics.pushState();
		if (dashes != null) {
			graphics.setLineDash(dashes);
		}
		if (this.img!=null){ // display an icon??
			super.FillFigure(graphics);}
		super.paintFigure(graphics);
		graphics.popState();
	}
	/*
	 * TO display with an image in the middle of the link
	 */
//	public void paintFigure(Graphics graphics) {
//		graphics.pushState();
//		if (dashes != null)
//			graphics.setLineDash(dashes);
//		MiddleEndpointLocator lo =new MiddleEndpointLocator (this,new Point(0,0));
//		Image im=LookForElement.createImage("icons/papyrus.gif");
//		// pour les angles il faut passer en AWT
//		graphics.drawImage(im, lo.getLocation());
//		super.paintFigure(graphics);
//		graphics.popState();
//	}
	
	
}